﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Dispatcher;

namespace FlightSearchServer
{
    class Caching : IParameterInspector
    {
        public Caching(string serverName, string alliance)
        {
            this.serverName = serverName;
            this.alliance = alliance;
        }

        public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
        {
            string key2 = "&";
            List<object> keys = (List<object>)correlationState;
            foreach( var s in keys) {
                key2 += s.ToString( ) + "&";
            }
            string key1 = String.Format("{0}&{1}", serverName, alliance);
            LocalClientCache.Instance.addEntry( key1, key2, (FlightRoutes)returnValue);
        }

        public object BeforeCall(string operationName, object[] inputs)
        {
            return new List<object>(inputs);
        }

        public string serverName { get; set; }

        public string alliance { get; set; }
    }
}
